package com.ky.facescan.api.verifier;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class HttpHostnameVerifier implements HostnameVerifier {
    @Override
    public boolean verify(String hostname, SSLSession session) {
//        try {
//            String peerHost = session.getPeerHost(); //服务器返回的主机名
//            String str_new = "";
//            X509Certificate[] peerCertificates = (X509Certificate[]) session.getPeerCertificates();
//            for (X509Certificate certificate : peerCertificates) {
//                X500Principal subjectX500Principal = certificate.getSubjectX500Principal();
//                String name = subjectX500Principal.getName();
//                String[] split = name.split(",");
//                for (String str : split) {
//                    if (str.startsWith("CN")) {//证书绑定的域名或者ip
//                        if (str.contains(hostname) && str.contains(peerHost)) {
//                            return true;
//                        }
//                    }
//                }
//            }
//        } catch (SSLPeerUnverifiedException e1) {
//            e1.printStackTrace();
//        }
        return true;
    }
}